import { Button, Flex, type TableColumnsType } from "antd"
import { type DataItem } from "./api";

interface ColumnsProps {
  handleEdit: (data: DataItem) => void
  handleDelete: (id: string) => void
  handleEnable: (data: DataItem) => void
}

export const columns: (props: ColumnsProps) => TableColumnsType = ({ handleDelete, handleEdit,handleEnable }) => [
  {
    title: '任务id',
    dataIndex: 'id',
    key: 'id',
    width: 100,
    hidden: true,
  },
  {
    title: '任务名称',
    dataIndex: 'taskName',
    key: 'taskName',
    width: 100,
  },
  {
    title: '用户',
    dataIndex: 'userNames',
    key: 'userNames',
    width: 200,
  },
  {
    title: '状态',
    dataIndex: 'enabled',
    key: 'enabled',
    render: (text: boolean) => {
      return text ? '启用' : '禁用';
    }
  },
  {
    title: '执行时间',
    dataIndex: 'taskTime',
    key: 'taskTime',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    render: (text: string) => {
      return new Date(text).toLocaleString();
    },
  },
  {
    title: '操作',
    dataIndex: 'actions',
    key: 'actions',
    render: (_: any, row: any) => {
      return <Flex>
        {
        <Button size="small" type="link" onClick={() => handleEnable(row)}>{!row.enabled ? '启用' : '禁用'}</Button>}
        <Button size="small" type="link" onClick={() => handleEdit(row)}>编辑</Button>
        <Button size="small" danger type="link" onClick={() => {
          handleDelete(row.id)
        }}>删除</Button>
      </Flex>
    },
  },
];
